import info from './dt-info.vue'
import infoItem from './dt-info-item.vue'
import infoEdit from './dt-info-edit.vue'
import infoEditGroup from './dt-info-edit-group.vue'
import infoEditText from './dt-info-edit-text.vue'

function mixin(Vue) {
  Vue.component('dt-info-edit', infoEdit)
  Vue.component('dt-info-edit-text', infoEditText)
  Vue.component('dt-info-edit-group', infoEditGroup)
  Vue.component('dt-info', info)
  Vue.component('dt-info-item', infoItem)
}

function validInfo(info, opts) {
  let newInfo = {}
  opts.forEach((opt) => {
    if (opt.data?.to && opt.data?.from) {
      let from = opt.data?.from(info)
      if (from) {
        Object.assign(newInfo, opt.data.to(from))
      }
    } else if (opt.key && info[opt.key]) {
      newInfo[opt.key] = info[opt.key]
    }
  })
  return newInfo
}

export default {
  mixin,
  validInfo
}
